package com.atguigu.spzx.user.controller;

import com.atguigu.spzx.model.dto.h5.UserRegisterDto;
import com.atguigu.spzx.model.entity.h5.UserInfo;
import com.atguigu.spzx.model.result.Result;
import com.atguigu.spzx.model.vo.h5.UserInfoVo;
import com.atguigu.spzx.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user/userInfo")
public class UserController {
    @Resource
    UserInfoService userInfoService;
    @Operation(summary = "查询用户信息回显接口")
    //auth: 以后需要登录验证的接口会在路径中添加一层auth    前端访问时需要再请求头携带token
    @GetMapping("auth/getCurrentUserInfo")
    public Result getCurrentUserInfo(@RequestHeader(value = "token" , required = false) String token){
        UserInfoVo userInfoVo = userInfoService.getCurrentUserInfo(token);
        return Result.ok(userInfoVo);
    }
    @Operation(summary = "登录接口")
    @PostMapping("/login")
    public Result login(@RequestBody UserInfo userInfo){
        String token = userInfoService.login(userInfo);
        return Result.ok(token);
    }
    @Operation(summary = "注册接口")
    @PostMapping("/register")
    public Result register(@RequestBody UserRegisterDto userRegisterDto){
        userInfoService.register(userRegisterDto);
        return Result.ok();
    }


}
